﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.SiteAdmin;
using Jzy.Model.SiteAdmin;
using Jzy.Core.Common.Web;
using Jzy.Core.Utility;

namespace Jzy.Web.SiteAdmin.FreindLink
{
    public partial class List : PageList
    {
        private FreindLinkBO _freindLink;
        private FreindLinkBO FreindLink
        {
            get
            {
                if (_freindLink == null)
                {
                    _freindLink = new FreindLinkBO();
                }
                return _freindLink;
            }

        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindView();
            }
            AddAttr();
            this.InitSelectID(hidSelectIDs);
            JSUtil.SetTableHeight("list", 60);
        }


        protected bool IsVisible(object imagePath)
        {
            if (imagePath == null || imagePath.ToString() == "")
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private void AddAttr()
        {
            JSUtil.DelConfirm(btnDelete, "友情链接");
            JSUtil.ClickBtn(lnkDelete, btnDelete);

            JSUtil.ShowForm(lnkAdd, "增加友情链接", null, "Edit.aspx", 400, 205);
        }

        private void BindView()
        {
            this.InitLV(lv, lvHeader);

            List<FreindLinkInfo> list = FreindLink.GetList();
            lv.DataSource = list;
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataBind();


            lblStatistic.Text = "[&nbsp;共<b> " + list.Count() + "</b>&nbsp;个链接&nbsp;]";

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs == "")
            {
                return;
            }
            this.FreindLink.Delete(strSelectIDs, true);
            BindView();
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }


        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                string strID = StrUtil.EncryptUrl(lv.DataKeys[((ListViewDataItem)e.Item).DataItemIndex]["ID"].ToString());
                HyperLink lnkEdit = (HyperLink)e.Item.FindControl("lnkEdit");

                string url = "Edit.aspx?ID=" + strID ;
                JSUtil.ShowForm(lnkEdit, "编辑友情链接", null, url, 400, 205);
            }
        }
    }
}
